// pages/myTask/myTask.js
import { request } from "../../utils/index.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:0, // 当前订单状态
    orderType:[
      {
        title:"全部",
        status:0
      },
      {
        title:"已报名",
        status:1
      },
      {
        title:"已录用",
        status:2
      },
      {
        title:"已到岗",
        status:3
      },
       {
        title:"已结算",
        status:4
      }
    ],
    orderList:[],
    page:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let status = options.status;
    // console.log(status)
    this.setData({
      status:parseInt(status)
    })

    // 当前订单为全部时请求
    if (status == 0) {
      this.getOrderList(0);
    }
  },

  onChange(event){
    this.data.page = 1;
    this.data.orderList = [];
    this.setData({status:event.detail.index});
    this.getOrderList(event.detail.index);
  },

   //  查询订单数据
   getOrderList (status) {
    var that = this;
    request({ url: "/api/apply/index", data:{status:status,page:that.data.page}})
    .then(result => {
      console.log(result)
      that.setData({
        orderList:that.data.orderList.concat(result.data.list)
      })
      wx.stopPullDownRefresh();
    })
  },

  // 点击撤销
  cancels(item){
    // console.log(item)
    let id = item.currentTarget.dataset.value.id
    var that = this;
    request({ url: "/api/apply/cancle", data:{id:id}})
    .then(result => {
      console.log(result)
      that.data.page = 1;
      that.data.orderList = [];
      that.getOrderList(that.data.status);
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.data.page = 1;
    this.setData({
      orderList:[]
    })
    this.getOrderList(this.data.status)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.page++;
    this.getOrderList(this.data.status)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})